package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.model.vo.UserInfoVoAge;
import com.tanhua.server.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingController {

    @Autowired
    private SettingService settingService;

    /**
     * 查询用户通用设置
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity settings(){
        SettingsVo settingsVo = settingService.querySettings();
        return ResponseEntity.ok(settingsVo);
    }

    /**
     * 设置陌生人问题
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity saveQuestions(@RequestBody Map<String,String> params){
        settingService.saveQuestions(params);
        return ResponseEntity.ok(null);
    }

    /**
     * 通知设置 - 保存
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity saveSettings(@RequestBody SettingsVo settingsVo){
        settingService.saveSettings(settingsVo);
        return ResponseEntity.ok(null);
    }

    /**
     * 黑名单 - 翻页列表
     * @return
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklistPage(@RequestParam(value = "page",defaultValue = "1") Long page,
                                        @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){

        pagesize = pagesize > 50 ? pagesize : 50;
        PageResult<UserInfoVoAge> pageResult = settingService.blacklistPage(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 黑名单 - 移除
     * @param uid
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity removeBlackList(@PathVariable("uid") Long uid){
        settingService.removeBlackList(uid);

        return ResponseEntity.ok(null);
    }


    /**
     * 修改手机号- 1 发送短信验证码
     * @return
     */
    @PostMapping("/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode(){
        settingService.sendVerificationCode();
        return ResponseEntity.ok(null);
    }


    /**
     * 修改手机号 - 2 校验验证码
     * @return
     */
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map<String,String> params){
        Map<String,Boolean> verification = settingService.checkVerificationCode(params);
        return ResponseEntity.ok(verification);
    }

    /**
     * 修改手机号 - 3 保存
     * @return
     */
    @PostMapping("/phone")
    public ResponseEntity updatePhone(@RequestBody Map<String,String> params){
        settingService.updatePhone(params);
        return ResponseEntity.ok(null);
    }

}
